package cate.game.play.util;

import cate.game.play.fighter.FighterPerformance;
import cate.game.play.fighter.HeroFighter;
import cate.game.play.part.BattleHero;
import cate.game.play.part.FightTeam;
import cate.game.play.part.PlaySide;
import cate.game.play.vo.PlaySideVO;
import cate.game.play.vo.RoleSnapShotVO;
import cate.game.role.RoleSnapshot;
import cp.solution.util.collection.ListKit;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class PlayUtils {

    public static PlaySide toPlaySide(PlaySideVO vo, boolean deepCopy) {
        if(vo == null) {
            return null;
        }
        PlaySide ps = new PlaySide();
        if(deepCopy) {
            ps.snapshot = toRoleSnapshot(vo.snapshot, true);
            ps.positionTid = vo.positionTid;
            ps.hs = ListKit.cloneList(vo.hs, BattleHero::copy);
            //ps.hallow = vo.hallow != null ? vo.hallow.copy() : null;
        } else {
            ps.snapshot = toRoleSnapshot(vo.snapshot, false);
            ps.positionTid = vo.positionTid;
            ps.hs = vo.hs;
           // ps.hallow = vo.hallow;
        }
        return ps;
    }

    public static RoleSnapshot toRoleSnapshot(RoleSnapShotVO vo, boolean deepCopy) {
        if(vo == null) {
            return null;
        }
        RoleSnapshot data = new RoleSnapshot();
        if(deepCopy) {
            data.uid = vo.uid;
            data.base = vo.base != null ? vo.base.copy() : null;
        } else {
            data.uid = vo.uid;
            data.base = vo.base;
        }
        return data;
    }

    public static long calcMpvScore(HeroFighter hf) {
        FighterPerformance p = hf.performance;
        return p.damage * 5 + p.heal * 2 + p.hurt * 3;
    }

    public static List<Integer> findProtoIds(FightTeam ft) {
        List<Integer> ids = new ArrayList<>();
        try {
            for(HeroFighter hf : ft.getAllHero()) {
                ids.add(hf.protoId);
            }
        } catch (Exception e) {
            log.info("", e);
        }
        return ids;
    }
}
